﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Smart.Controls
{
    public class SuperTextBox : TextBox
    {
        bool _keyboardShow = false;
        bool _harfGirilebilir = true;
        bool _prefixCevrilsin = true;

        public bool KeyBoardShow { get { return _keyboardShow; } set { _keyboardShow = value; } }
        public bool HarfGirilebilir { get { return _harfGirilebilir; } set { _harfGirilebilir = value; } }
        public bool PrefixDegistirilsin { get { return _prefixCevrilsin; } set { _prefixCevrilsin = value; } }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            if (_keyboardShow)
                Sip.Show();
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            if (_keyboardShow)
                Sip.Hide();
            if (!_harfGirilebilir)
            {
                string deger = string.Empty;
                foreach (Char c in this.Text.ToCharArray())
                {
                    if (char.IsNumber(c) || c == '.' || c == ',')
                        deger += c.ToString();
                }
                this.Text = deger;
            }
            if (_prefixCevrilsin)
                this.Text = this.Text.Replace('*', '%');
        }
    }
}
